package com.jumi.microservice.controller.admin;

import com.jumi.microservice.common.base.BaseController;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 123
 */
@RestController
@RequestMapping("/rocketMq")
public class TestRocketMqController extends BaseController {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 发送一个批量消息
     * 验证rocketmq顺序消费
     */
    @RequestMapping("/batch/send")
    public String sendBatchMsg() {
        /*
         * hashKey: 为了保证报到同一个队列中，将消息发送到主题上
         */
        String idStr = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20";
        String[] idArr = idStr.split(",");
        for (int i = 0; i < idArr.length; i++) {
            rocketMQTemplate.syncSendOrderly("testBatch", idArr[i], "testBatch");
        }
        return "success";
    }
}
